home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2006 November
/
PCWorld_2006-11_cd.bin
/
domacnost a kancelar
/
findgraph
/
fgraph.exe
/
{app}
/
UserModels
/
UserModels.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2004-10-06
|
6KB
|
216 lines
// UserModels.cpp : Defines the entry point for the USERMODELS.DLL application.
//
//
/******************************************************************************
* 'User model' Plug-In DLL
* for use with C/C++
*
* How do I include my equations or curve fitting model?
* To include your equations into FindGraph with a 'user model' plugin
* follow these steps:
* 1. Open this project UserModels.dsp;
* 2. Open files Models.cpp and Models.h;
* 3. Select any name of your model. For example, "MyEquation";
* 4. Add string DEFINE_MODEL(MyEquation) in Models.h;
* 5. Add string MODELS_LIST_ADD(id, MyEquation) in Models.cpp;
* Replace id with unical number less 999, for example '101'.
* 6. Prepare functions:
* MyEquation_Name
* MyEquation_Form
* MyEquation_Calc
* MyEquation_Check
* MyEquation_Defau
* Use functions Poly_Name, Poly_Form, Poly_Calc, Poly_Check, Poly_Defau
* in Models.cpp as template.
* 7. Compile this USERMODELS.DLL
* 8. Place it in the program FindGraph subfolder "Models".
*
* To test DLL:
* 1. Restart FundGraph;
* 2. Start The Wizard of approximation;
* 3. On step 2 choose function 'Non-linear';
* 4. On step 3 select family 'User Models'.
* If all right, on step 3 your function will appear in functions list.
*
* Alternatively, if you're unaccustomed to writing DLL's
* we'd be happy to produce a plugin for licensed users at no charge,
* provided that you can furnish the curve fitting model details:
* 1. Model Title.
* 2. Equation of function in form Y = f(X,a,b,c,d,g,h,k,l,m).
* 3. Default parameters (a,b,c,d,g,h,k,l,m) values.
*
* Contact us for more information. E-mail: serg@uniphiz.com
*
******************************************************************************/
//--------------------------------------------------------------------------------------
#include "stdafx.h"
#include <tchar.h>
#include "models.h"
HINSTANCE g_hInstance=NULL;
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
g_hInstance = (HINSTANCE )hModule;
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
////////////////////////////////////////////////////////////////////////////////////////////////
// All function return 1 if result
//
//Group Name
// nIdList Unused
//
__declspec(dllexport) int FunctionGroupDesc(int nIdList, LPTSTR lpszInfo, int nLen)
{
if (lpszInfo==NULL) return -1;
lstrcpyn(lpszInfo, _T("User Models"), nLen);
return 1;
}
// nIdList Unused
//
__declspec(dllexport) int FunctionGroupList(int nIdList, int *pnIds, int *pNumber)
{
if (pnIds==NULL) return -1;
if (FittingModelsList(nIdList, pnIds, pNumber))
return 1;
return 0;
}
// Fill lpszName with 'Model name'
// Example: "Linear"
//
__declspec(dllexport) int FunctionName(int nIdFunc, LPTSTR lpszName, int nLen)
{
if (lpszName==NULL) return -1;
FuncDesc *pDesc = PFittingDescInId(nIdFunc);
if (NULL != pDesc && NULL != pDesc->m_pFuncName)
{
pDesc->m_pFuncName(lpszName, nLen);
return 1;
}
return 0;
}
// Fill lpszForm with 'Formula'
// Example: "aa*x+bb"
// Important: replace all symbols a,b,c,... with aa,bb,cc...
// nIdEquation Unused
//
__declspec(dllexport) int FunctionForm(int nIdFunc, int nIdEquation, LPTSTR lpszForm, int nLen)
{
if (lpszForm==NULL) return -1;
FuncDesc *pDesc = PFittingDescInId(nIdFunc);
if (NULL != pDesc && NULL != pDesc->m_pFuncForm)
{
pDesc->m_pFuncForm(lpszForm, nLen);
return 1;
}
return 0;
}
// nIdEquation - parameter Unused
//
PToFuncCalc PFunctionInIdCalc(int nIdFunc, int nIdEquation)
{
FuncDesc *pDesc = PFittingDescInId(nIdFunc);
return (NULL != pDesc ) ?pDesc->m_pFuncCalc :NULL;
}
// nIdEquation - parameter Unused
//
__declspec(dllexport) int FunctionCalc(int nIdFunc, int nIdEquation, double *pfParams, int nParams, double u, double *x, double *y)
{
PToFuncCalc pFuncCalc = PFunctionInIdCalc(nIdFunc, nIdEquation);
if (pFuncCalc != NULL)
return pFuncCalc(pfParams, nParams, u, x, y);
*x = u; *y = 0.;
return -1;
}
// nIdEquation - parameter Unused
//
__declspec(dllexport) int FunctionFunc(int nIdFunc, int nIdEquation, long *pFunction)
{
PToFuncCalc pFuncCalc = PFunctionInIdCalc(nIdFunc, nIdEquation);
pFunction = (long *)pFuncCalc;
if (pFuncCalc != NULL) return 1;
return -1;
}
// Unused
//
__declspec(dllexport) int FunctionPict(int nIdFunc, int nIdEquation)
{
return 0;
}
// return the number of parameters actually used
// set other parameters to 0
//
__declspec(dllexport) int FunctionCheck(int nIdFunc, int nIdEquation, double *pfParams, int nParams)
{
FuncDesc *pDesc = PFittingDescInId(nIdFunc);
if (NULL != pDesc && NULL != pDesc->m_pFuncCheck)
{
return pDesc->m_pFuncCheck(pfParams, nParams);
}
return -1;
}
// Fill pfParams with default values
// to start fitting
// px[4]: xMin, xMax, xMed, x(yMed)
// py[4]: yMin, yMax, yMed, y(xMed)
//
__declspec(dllexport) int FunctionDefaupa(int nIdFunc,
BOOL bNormed, double *px, double *py,
double *pfParams, int nParams)
{
FuncDesc *pDesc = PFittingDescInId(nIdFunc);
if (NULL != pDesc && NULL != pDesc->m_pFuncDefau)
{
if (NULL==px || NULL==py)
bNormed = TRUE;
return pDesc->m_pFuncDefau(pfParams, nParams, px, py, bNormed);
}
return -1;
}
// Fill pfParams with default Normed values
// to start fitting
//
__declspec(dllexport) int FunctionDefault(int nIdFunc, double *pfParams, int nParams)
{
return FunctionDefaupa(nIdFunc, TRUE, NULL, NULL, pfParams, nParams);
}